package leetcode.biweekly.week80;

import java.util.Arrays;

//Solution2Test
public class Solution2 {

	// Solution2Test
	public int[] successfulPairs(int[] spells, int[] potions, long success) {
		int len = spells.length;
		int[] ans = new int[len];
		Arrays.sort(potions);
		int R = potions.length - 1;
		int l = 0, r = R;
		for (int i = 0; i < len; i++) {
			long sp = spells[i];
			l = 0;
			r = R;
			int cur = 0;
			while (l <= r) {
				int mid = l + ((r - l) >> 1);
				if (1L * potions[mid] * sp >= success) {
					cur = R - mid + 1;
					r = mid - 1;
				} else {
					l = mid + 1;
				}
			}
			ans[i] = cur;
		}
		return ans;
	}

}
